import { Badge, Space, TableColumnsType, Tag, Tooltip, Typography } from 'antd'
import type { ITableData } from './types'
import { STATUSBAND } from '@/constant'
import dayjs from 'dayjs'
import { NavigateFunction } from 'react-router-dom'
export const useIndexColumns = (
  navigate: NavigateFunction,
  onStatus: (info: ITableData) => void,
  viewLogs: (info: ITableData) => void,
): TableColumnsType<ITableData> => [
  {
    title: '供应商编码',
    dataIndex: 'supplierCode',
    key: 'supplierCode',
    align: 'center',
    fixed: 'left',
    width: 150,
    render: (info, rows) => {
      return (
        <Typography.Link
          ellipsis
          onClick={() => navigate('/supplier/create/detail?supplierId=' + rows.supplierId)}
          style={{ paddingLeft: 12, paddingRight: 12 }}
        >
          {info}
        </Typography.Link>
      )
    },
  },
  {
    title: '供应商名称',
    dataIndex: 'supplierName',
    key: 'supplierName',
    align: 'center',
    fixed: 'left',
    width: 300,
    ellipsis: {
      showTitle: false,
    },
    render: (info) => {
      return info ? (
        <Tooltip placement="top" title={info}>
          {info}
        </Tooltip>
      ) : (
        '-'
      )
    },
  },
  {
    title: '简称',
    dataIndex: 'supplierShortName',
    key: 'supplierShortName',
    align: 'center',
    width: 150,
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '推送状态',
    dataIndex: 'pushErrorMsg',
    key: 'pushErrorMsg',
    align: 'center',
    width: 150,
    render: (info) => {
      return info ? (
        <Tooltip placement="top" title={info}>
          <Tag color="error">推送CB失败</Tag>
        </Tooltip>
      ) : (
        '-'
      )
    },
  },
  {
    title: '供应商分类',
    dataIndex: 'supplierClassificationCodeName',
    key: 'supplierClassificationCodeName',
    align: 'center',
    width: 150,
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '可供应大类',
    dataIndex: 'maiClassCodeName',
    key: 'maiClassCodeName',
    align: 'center',
    width: 150,
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '采购模式',
    dataIndex: 'purchaseTypeNames',
    key: 'purchaseTypeNames',
    align: 'center',
    width: 150,
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '区域',
    dataIndex: 'locationCodeName',
    key: 'locationCodeName',
    align: 'center',
    width: 150,
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '开始合作时间',
    dataIndex: 'cooperateStartDate',
    key: 'cooperateStartDate',
    align: 'center',
    width: 150,
    render: (info) => {
      return info ? dayjs(info).format('YYYY-MM-DD') : '-'
    },
  },
  {
    title: '合作状态',
    dataIndex: 'cooperateStatusName',
    key: 'cooperateStatusName',
    align: 'center',
    width: 150,
    render: (info) => {
      return info ? info : '-'
    },
  },
  // {
  //   title: '供应商评级',
  //   dataIndex: 'levelCode',
  //   key: 'levelCode',
  //   align: 'center',
  //   width: 150,
  //   render: (info) => {
  //     return info ? info : '-'
  //   },
  // },
  // {
  //   title: '联系人',
  //   dataIndex: 'contactName',
  //   key: 'contactName',
  //   align: 'center',
  //   width: 150,
  //   render: (info) => {
  //     return info ? info : '-'
  //   },
  // },
  // {
  //   title: '联系方式',
  //   dataIndex: 'contactPhone',
  //   key: 'contactPhone',
  //   align: 'center',
  //   width: 150,
  //   render: (info) => {
  //     return info ? info : '-'
  //   },
  // },
  // {
  //   title: '联系地址',
  //   dataIndex: 'contactAddress',
  //   key: 'contactAddress',
  //   align: 'center',
  //   width: 130,
  // },
  {
    title: '状态',
    dataIndex: 'useStatus',
    key: 'useStatus',
    align: 'center',
    width: 150,
    render: (info) => {
      return <Badge status={info == 1 ? 'success' : 'error'} text={STATUSBAND[info] || '-'} />
    },
  },
  {
    fixed: 'right',
    title: '操作',
    width: 220,
    align: 'center',
    render: (info) => {
      return (
        <Space size="large">
          <Typography.Link onClick={() => viewLogs(info)}>查看日志</Typography.Link>
          {/* <Popconfirm
            title={`确认${DIS_STATUSBANDBTNTEXT[info.status]}吗？`}
            onConfirm={() => onStatus(info)}
            okText="确认"
            cancelText="取消"
          >
            <Typography.Link type={info.status == 1 ? 'danger' : undefined}>
              {DIS_STATUSBANDBTNTEXT[info.status]}
            </Typography.Link>
          </Popconfirm> */}
        </Space>
      )
    },
  },
]
